package org.summer.generator.writer.impl;

import org.summer.generator.log.Logger;
import org.summer.generator.log.LoggerManager;
import org.summer.generator.vo.Column;
import org.summer.generator.vo.MethodInfo;
import org.summer.generator.writer.AbstractFileWriter;
import org.summer.generator.writer.AbstractJavaFileWriter;

/**
 * sql数据表对java实体类映射文件写入处理器
 */
public class EntityFileWriter extends AbstractJavaFileWriter {
    private static final Logger log = LoggerManager.getLogger(EntityFileWriter.class);
    @Override
    public void execute() {
        String packageDefinition = getPackageDefinition(project.getEntityPackageName());
        channel.writerNewline(packageDefinition);
        channel.writerEmptyLine();
        channel.writerNewline("import lombok.Data;");
        channel.writerNewline("import java.io.Serializable;");
        channel.writerNewline("import java.time.LocalDateTime;");
        channel.writerEmptyLine();
        channel.writerNewline(CLASS_REMARK.formatted(table.getRemark() + "实体类"));
        channel.writerNewline("@Data");
        channel.writerNewline("public class %s implements Serializable {".formatted(table.getTableUpperName()));
        table.getColumns().forEach(this::createFiled);

        channel.writerNewline(BLOCK_END);
    }

    private void createFiled(Column column){
        String r = "    /**\n" +
                "     * " + column.getRemark() + "\n" +
                "     */";
        String fs = "\tprivate %s %s;"
                .formatted(column.getJavaType(),column.getColumnName());
        channel.writerNewline(r);
        channel.writerNewline(fs);
    }

    @Override
    protected void writerMethod(MethodInfo method, String previousObject, String loadMethodName) {

    }
}
